package sharetime.core;

import java.io.Serializable;
import java.util.Date;

import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;

import org.hibernate.search.annotations.DocumentId;

import sharetime.web.view.flexjson.JsonAttribute;

@MappedSuperclass
public abstract class EntityObject implements Serializable {
	protected Long id;

	protected Date creationDate;

	protected Date lastModificationDate;

	@Id
	@DocumentId
	@GeneratedValue(strategy = GenerationType.AUTO)
	public Long getId() {
		return id;
	}

	@JsonAttribute(include = false)
	public Date getCreationDate() {
		return creationDate;
	}

	@JsonAttribute(include = false)
	public Date getLastModificationDate() {
		return lastModificationDate;
	}

	public void setCreationDate(Date creationDate) {
		this.creationDate = creationDate;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public void setLastModificationDate(Date lastModificationDate) {
		this.lastModificationDate = lastModificationDate;
	}

	public abstract String toString();

	public boolean equals(Object o) {
		if (this == o)
			return true;
		if (!(o instanceof EntityObject))
			return false;
		EntityObject entityObject = (EntityObject) o;
		return id == entityObject.getId();
	}

	public int hashCode() {
		long idValue;
		if (null != id) {
			idValue = id.longValue();
		} else {
			idValue = 0;
		}
		return (int) (idValue ^ idValue >>> 32);
	}
}
